package qiniu

import (
	"fmt"
	"strings"
)

const (
	vframeImageHost = "https://pp.jxkfxz.com"
	vframeImageKey  = "vframe/%s_0.jpg"
)

func GenVideoVframe0Url(key string) string {
	name := getFileNameWithoutSuffix(key)
	imageKey := fmt.Sprintf(vframeImageKey, name)
	return fmt.Sprintf("%s/%s", vframeImageHost, imageKey)
}

func GenVideoVframe0Key(key string) string {
	name := getFileNameWithoutSuffix(key)
	return fmt.Sprintf(vframeImageKey, name)
}

func getFileNameWithoutSuffix(key string) string {
	if len(key) == 0 {
		return ""
	}

	index := strings.LastIndex(key, "/")
	if index != -1 {
		key = key[index+1:]
	}

	index = strings.LastIndex(key, ".")
	if index == -1 {
		return ""
	}
	return key[:index]
}
